package common.sysconfig;


import common.intercepter.Interceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Resource
    Interceptor interceptor;

    private static final List<String> EXCLUDE_PATH = Arrays.asList("/**/*.js", "/**/*.html", "/**/*.css");


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptor)
                .excludePathPatterns(EXCLUDE_PATH)
                .excludePathPatterns("/api-docs/**")
                .excludePathPatterns("/v3/api-docs/**")
                .excludePathPatterns("/swagger-resources/**")
                .excludePathPatterns("/swagger-ui/**")
                .excludePathPatterns("/webjars/**")
                .excludePathPatterns("/doc.html")
                .excludePathPatterns("/null/swagger-resources/**")
                .excludePathPatterns("/pubmed/**")
                .excludePathPatterns("/pubmed/*")
                .excludePathPatterns("/download/*")
                .addPathPatterns("/**");

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //文件磁盘图片url 映射
        //配置server虚拟路径，handler为前台访问的目录，locations为files相对应的本地路径
//        registry.addResourceHandler("/upload/**").addResourceLocations("upload");
        // 下面是为了解决高版本sb 与 swagger 兼容性问题 2024年3月5日09:35:45  张哥改了一个高版本本来想着降低回去 但是发现无法 启动了
//        registry.addResourceHandler("/**").addResourceLocations(
//                "classpath:/static/");
//        registry.addResourceHandler("swagger-ui.html", "doc.html").addResourceLocations(
//                "classpath:/META-INF/resources/");
//        registry.addResourceHandler("/webjars/**").addResourceLocations(
//                "classpath:/META-INF/resources/webjars/");
    }
}